﻿using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;

namespace CSCV.Group8.BlogRollWebPart.VWP
{
    [ToolboxItemAttribute(false)]
    public class VWP : WebPart
    {
        // Visual Studio might automatically update this path when you change the Visual Web Part project item.
        private const string _ascxPath = @"~/_CONTROLTEMPLATES/CSCV.Group8.BlogRollWebPart/VWP/VWPUserControl.ascx";
        Presenter.BRPresenter presenter;
        protected override void Render(HtmlTextWriter writer)
        {

            //if(presenter!=null)
            //    presenter.InitView();
            base.Render(writer);

        }

        protected override void CreateChildControls()
        {
            //CssRegistration.Register(@"~sitecollection/Style Library/CSCV.SPBranding/css/styles.css");
            Control control = Page.LoadControl(_ascxPath);
            Model.BRModel model = new Model.BRModel(StrBlogUrl, INumberOfPost, INumberOfWordPerPost, BShowAvatar);
            InitBlogRoll(control as Interface.IBRView, model);
            Controls.Add(control);
        }
        private void InitBlogRoll(Interface.IBRView view, Model.BRModel model)
        {
            presenter = new Presenter.BRPresenter(view, model as Interface.IBRModel);
            view.AttachPresenter(presenter);
            presenter.InitView();
        }

        #region WebPart properties
        /// <summary>
        /// Blog urls, separate by comma
        /// </summary>
        [Category("Blog Roll Web Part Settings"),
        Personalizable(PersonalizationScope.User),
        WebBrowsable,
        WebDisplayName("Blog urls: :"),
        WebDescription("Please type your blog url which you want to roll (separate which comma)")]
        public string StrBlogUrl { get; set; }

        /// <summary>
        /// Number of post to be display by blog roll web part
        /// </summary>
        [Category("Blog Roll Web Part Settings"),
        Personalizable(PersonalizationScope.User),
        WebBrowsable,
        WebDisplayName("Number of Posts to be display:"),
        WebDescription("Please type your number of blog post which you want to be roll integer")]
        public int INumberOfPost
        { get; set; }

        /// <summary>
        /// Number of words per post body to be display
        /// </summary>
        [Category("Blog Roll Web Part Settings"),
        Personalizable(PersonalizationScope.User),
        WebBrowsable,
        WebDisplayName("Number of words to be displayed per post :"),
        WebDescription("Please type your number of words to be displayed per post")]
        public int INumberOfWordPerPost
        {
            get;
            set;
        }

        /// <summary>
        /// Is show the user profile setting
        /// </summary>
        [Category("Blog Roll Web Part Settings"),
        Personalizable(PersonalizationScope.User),
        WebBrowsable,
        WebDisplayName("Show user picture"),
        WebDescription("Check: Show/ Uncheck: Hide")]
        public bool BShowAvatar { get; set; }

        #endregion
    }
}
